// 实现这个项目的构建任务
const fs = require('fs')
exports.foo = done => {
  console.log('test')
  done() //标识任务完成
}

exports.default = done => {
  console.log('default')
  done()
}

const gulp = require('gulp')

gulp.task('bar', done => { // 不推荐
  console.log('bar')
  done()
})

//series  依次按顺序执行任务
//parallel 并行？同步执行任务


exports.callbak = done => {
  console.log('callback')
  done()
}
exports.callbak_error = done => {
  console.log('callback err')
  done(new Error('task err'))
}

exports.promise = done => {
  console.log('promise')
  return Promise.resolve()
}
//异步

const timeout = time => {
  return new Promise((resolve => {
    setTimeout(resolve, time)
  }))
}
exports.async = async () => {
  await timeout(2000)
  console.log('async task')
}

// exports.stream = () => {
//   const readStream = fs.createReadStream('package.json')
//   const writeStream = fs.createWriteStream('temp.txt')
//   readStream.pipe(writeStream)
//   return readStream
// }

exports.stream = done => {
  const readStream = fs.createReadStream('package.json')
  const writeStream = fs.createWriteStream('temp.txt')
  readStream.pipe(writeStream)
  readStream.on('end', () => {
      done()
    }
  )
}



